package layui.controller.product;

import com.google.gson.Gson;
import layui.dao.ProductTypeDao;
import layui.dao.impl.ProductTypeDaoImpl;
import layui.entity.ProductType;
import layui.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author lzp
 * @Date 2023-11-21
 */

@WebServlet("/admin/product/product_type_list")
public class FindAllProductTypeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        ProductTypeDao productTypeDao = new ProductTypeDaoImpl();
        List<ProductType> list = productTypeDao.selectAll();

        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg("success");
        responseData.setData(list);

        String json = new Gson().toJson(responseData);
        PrintWriter out = resp.getWriter();
        out.print(json);
        out.flush();
        out.close();


    }
}
